package com.example.mapstructexample.mapper;

import com.example.mapstructexample.bean.Car;
import com.example.mapstructexample.bean.Student;
import com.example.mapstructexample.vo.StudentVO;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
import org.mapstruct.Mappings;
import org.mapstruct.factory.Mappers;

import java.util.List;

@Mapper
public interface StudentMapper {
    //映射器工厂
    StudentMapper INSTANCE = Mappers.getMapper(StudentMapper.class);

    StudentVO toStudentVo(Student student);


    @Mappings({@Mapping(source = "student.name", target = "name")
            , @Mapping(source = "student.age", target = "age")
            , @Mapping(source = "car.name", target = "carName")
            , @Mapping(source = "car.color", target = "carColor")})
    StudentVO toStudentVo(Student student, Car car);

    @Mappings({@Mapping(source = "teacher.name", target = "teacherVo.name")
            , @Mapping(source = "teacher.age", target = "teacherVo.age")})
    StudentVO toStudentVoNested(Student student);

}
